package doorwifi.wd.patientsation.peripheral.mainapp.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
//import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;

import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.callSickbedInfoAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.Bean.CallLineUpInfo;
import doorwifi.wd.patientsation.peripheral.mainapp.Bean.illnessRoom;
import doorwifi.wd.patientsation.peripheral.mainapp.Bean.patientBedInfo;
import doorwifi.wd.patientsation.peripheral.mainapp.Bean.patientInfo;
import doorwifi.wd.patientsation.peripheral.mainapp.R;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.CallLineUpInfoAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.illnessDoorAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.patientInfoAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.utils.GridSpacingItemDecoration;
import doorwifi.wd.patientsation.peripheral.mainapp.utils.UIUtils;

/**
 * Created by xuhuan on 2017/7/6.
 *
 * 呼叫病床
 */

//@ContentView(R.layout.xh_call_sickbed_layout)//加载布局
public class CallSickbed extends Fragment implements illnessDoorAdapter.illnessDoorItemOnclickListener {

    @ViewInject(R.id.illnessRoom_recyclerview)
    private RecyclerView illnessRoom_recyclerview;

    @ViewInject(R.id.illnessBed_recyclerview)
    private RecyclerView illnessBed_recyclerview;

    @ViewInject(R.id.call_line_up_info_listview)
    private ListView call_line_up_info_listview;

    @ViewInject(R.id.is_telephone_info_listview)
    private ListView is_telephone_info_listview;

    private View view;
    private LinearLayoutManager manager;
    private ArrayList<illnessRoom> roomList;
    private ArrayList<patientBedInfo> callSickbedInfoAdapterList;
    private patientBedInfo patientBedInfo;
    private ArrayList<illnessRoom>bedList;
    private illnessRoom room;
    private illnessDoorAdapter illnessDoorAdapter;
    private CallLineUpInfo lineUpInfo;
    private ArrayList<CallLineUpInfo> lineUpInfoList;
    private CallLineUpInfoAdapter lineUpinfoAdapter;
    private patientInfo patientInfo;
    private ArrayList<patientInfo>patientInfoList;
    private patientInfoAdapter patientInfoAdapter;

    private callSickbedInfoAdapter callSickbedInfoAdapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.xh_call_sickbed_layout,null);
        x.view().inject(this,view);

        //初始化病房数据
        initIllnessRoomView();
        //初始化病床数据
        initIllnessBedView();
        //初始化呼叫排队信息栏
        initCallLineUpInfo();
        //初始化通话信息栏
        initIsTelInfo();

        return view;//fragment注解
    }

    private void initIsTelInfo() {
        getPatientInfo();
        patientInfoAdapter = new patientInfoAdapter(getActivity(),patientInfoList);
        is_telephone_info_listview.setAdapter(patientInfoAdapter);

    }

    private void getPatientInfo() {
        patientInfoList = new ArrayList<patientInfo>();
//        patientRoom patientBed name sex age ruyuanTime zhuzhi_doctor nic theIllness nursingLevel diet allergy quarantine
        patientInfo = new patientInfo();
        patientInfo.setPatientRoom("1房");
        patientInfo.setPatientBed("2床");
        patientInfo.setName("张三");
        patientInfo.setSex("男");
        patientInfo.setAge("18");
        patientInfo.setRuyuanTime("2017-01-01");
        patientInfo.setZhuzhi_doctor("王XX");
        patientInfo.setNic("李XX");
        patientInfo.setTheIllness("感冒");
        patientInfo.setNursingLevel("一级");
        patientInfo.setDiet("流食");
        patientInfo.setAllergy("是");
        patientInfo.setQuarantine("是");
        patientInfoList.add(patientInfo);
    }

    //获得呼叫排队信息栏数据
    private void initCallLineUpInfo() {
        getLineUpInfoData();
        lineUpinfoAdapter = new CallLineUpInfoAdapter(getActivity(),lineUpInfoList);
        call_line_up_info_listview.setAdapter(lineUpinfoAdapter);
    }

    public void getLineUpInfoData() {
        lineUpInfoList = new ArrayList<CallLineUpInfo>();
       for (int i = 0; i < 3; i ++){
           lineUpInfo = new CallLineUpInfo();
           lineUpInfo.setDate("2017-07-11");
           lineUpInfo.setTime("09:15:15");
           lineUpInfo.setIllnessRoom("102房");
           lineUpInfo.setIllnessBed(i+"房正在呼叫");
           lineUpInfoList.add(lineUpInfo);
       }
    }
    //获得病床数据
    private void initIllnessBedView() {
        getIllnessBedData();
//        manager = new LinearLayoutManager(getActivity());
//        illnessBed_recyclerview.setLayoutManager(new GridLayoutManager(getActivity(),6));
//        illnessDoorAdapter = new illnessDoorAdapter(getActivity(),roomList);
//        illnessBed_recyclerview.setAdapter(illnessDoorAdapter);
//        illnessBed_recyclerview .addItemDecoration(new GridSpacingItemDecoration(6,10,true));
////        illnessBed_recyclerview.addItemDecoration(new DividerGridItemDecoration(getActivity()));
//        illnessDoorAdapter.setillnessDoorOnItemClickListener(this);


        manager = new LinearLayoutManager(getActivity());
        illnessBed_recyclerview.setLayoutManager(new GridLayoutManager(getActivity(),6));
        callSickbedInfoAdapter = new callSickbedInfoAdapter(getActivity(),callSickbedInfoAdapterList);
        illnessBed_recyclerview.setAdapter(callSickbedInfoAdapter);
        illnessBed_recyclerview .addItemDecoration(new GridSpacingItemDecoration(6,10,true));
    }
    private void getIllnessBedData(){
//       roomList = new ArrayList<illnessRoom>();
//        for(int i = 1; i < 7; i ++){
//            room = new illnessRoom();
//            room.setIllnessNumber(i+"床");
//            roomList.add(room);
//        }

        callSickbedInfoAdapterList = new ArrayList<patientBedInfo>();
        for(int i = 1; i < 7; i ++){
            patientBedInfo = new patientBedInfo();
            patientBedInfo.setCall("");
            patientBedInfo.setNursingLevel("");
            patientBedInfo.setNursingWork("");
            patientBedInfo.setPatientBedNum(i+"床");
            callSickbedInfoAdapterList.add(patientBedInfo);
        }
    }
    private void initIllnessRoomView() {
        getIllnessRoomData();
        manager = new LinearLayoutManager(getActivity());
        //设置布局管理器
//        illnessDoor_recyclerview.setLayoutManager(manager);
        illnessRoom_recyclerview.setLayoutManager(  new GridLayoutManager(getActivity(),8));
        illnessDoorAdapter = new illnessDoorAdapter(getActivity(),bedList);
        illnessRoom_recyclerview.setAdapter(illnessDoorAdapter);
//        illnessRoom_recyclerview.addItemDecoration(new DividerGridItemDecoration(getActivity()));GridSpacingItemDecoration
        illnessRoom_recyclerview.addItemDecoration(new GridSpacingItemDecoration(8,10,true));
        illnessDoorAdapter.setillnessDoorOnItemClickListener(this);
    }

    //获得病房数据
    private void getIllnessRoomData(){
        bedList = new ArrayList<illnessRoom>();
        for(int i = 100; i < 150; i ++){
            room = new illnessRoom();
            room.setIllnessNumber(i+"房");
            bedList.add(room);
        }

    }

    @Override
    public void onSickDoorItemClick(View view, int position) {

        UIUtils.showToast(getActivity(),position+"");
    }


}
